<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class News_report extends MX_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model(array('admin_commoncall','admin_settings_model','admin_review_model','admin_news_model','admin_counter_model'));
		$this->load->library('pagination');
		//$this->admin_commoncall->check_admin_login();
		$this->template->set_theme('admin');
		$this->template->set_layout('default');
		//$this->template->set_partial('side_menu','layouts/side_menu');
		//$this->template->set_partial('nav_bar','layouts/nav_bar');

	}

	function index()
	{


		//-- Default Value --//
		$status=51;
		$featured=false;
		$search = "";

		if($this->input->post('order')){
			$order = $this->input->post('order');

			switch ($order) {
				case 'active':
					$status = 51;
					break;
				case 'inactive':
					$status = 1;
					break;
				case 'featured':
					$status = 51;
					$featured=true;
					break;
			}
		}

		$offset = 0 + $this->uri->segment(5);
		$config['base_url'] = base_url() . 'secure/reports/news_report/index';
		$total = $this->admin_counter_model->count_all_record('news');

		$perpage = 4;
		$config['per_page'] = $perpage;
		$config['total_rows'] = $total;
		$config['uri_segment'] = '5';


		if($status==51){

			$data['news']['all'] = $this->admin_news_model->get_news_report($featured = $featured, $status = $status, $perpage, $offset);

			$this->pagination->initialize($config);
		}
		else {
			$status=1;
			$offset = 0 + $this->uri->segment(5);
			$config['base_url'] = base_url() . 'secure/reports/news_report/inactive';
			$total = $this->admin_counter_model->count_inactive_news_report($status);
				
			//print $total;
			//die();
			$perpage = 4;
			$config['per_page'] = $perpage;
			$config['total_rows'] = $total;
			$config['uri_segment'] = '5';
				
			$data['news']['all'] = $this->admin_news_model->get_inactive_news_report($featured = $featured, $status = $status, $perpage, $offset);
				
			$this->pagination->initialize($config);
				
		}
		if($this->input->post('search')){
			$search = 	trim($this->input->post('search'));
			$data['news']['all'] = $this->admin_news_model->search($search = $search);
			//print $search;
		}
		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		//->set_partial('footer', 'footer/footer')
		->build('reports/news_report',$data);
	}



	function inactive()
	{
		//-- Default Value --//
		$status=1;
		$featured=false;
		$search = "";

		if($this->input->post('order')){
			$order = $this->input->post('order');

			switch ($order) {
				case 'active':
					$status = 51;
					break;
				case 'inactive':
					$status = 1;
					break;
				case 'featured':
					$status = 51;
					$featured=true;
					break;
			}
		}

		$status=1;
		$offset = 0 + $this->uri->segment(5);
		$config['base_url'] = base_url() . 'secure/reports/news_report/inactive';
		$total = $this->admin_counter_model->count_inactive_news_report($status);
			
		//print $total;
		//die();
		$perpage = 4;
		$config['per_page'] = $perpage;
		$config['total_rows'] = $total;
		$config['uri_segment'] = '5';
			
		$data['news']['all'] = $this->admin_news_model->get_inactive_news_report($featured = $featured, $status = $status, $perpage, $offset);
			
		$this->pagination->initialize($config);
			

		if($this->input->post('search')){
			$search = 	trim($this->input->post('search'));
			$data['news']['all'] = $this->admin_news_model->search($search = $search);
			//print $search;
		}
		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		//->set_partial('footer', 'footer/footer')
		->build('reports/news_report',$data);
	}

	function action()
	{
		$status=NULL;
		$id=NULL;

		if($this->input->post('action')){
			$action = $this->input->post('action');
			$id = $this->input->post('news_id');

			switch ($action) {
				case 'active':
					$status = 51;
					$this->admin_news_model->change_status($status,$id);


					break;
				case 'inactive':
					$status = 1;
					$this->admin_news_model->change_status($status,$id);
					break;
				case 'delete':

					$this->admin_news_model-> delete_news($id);
					break;
				case 'edit':

					$url= 'secure/news/news_management/edit_news/'.$id;
					redirect($url);
					break;
			}
		}

		redirect('secure/reports/news_report');
	}

	function change_news_status($status=NULL,$id=NULL){
		$this->admin_news_model->change_news_status($id,$status);
		redirect('secure/reports/news_report');
	}

}